package com.lsa.tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ToArraysAsList {
	public static void main(String[] args) throws IOException {
		InputStream in = ToArraysAsList.class.getResourceAsStream("ToArraysAsList.txt");
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

		String line = null;
		while((line = br.readLine()) != null) {
			System.out.println(String.format("Arrays.asList(%s)", toArraysAsList(line)));
		}
	}

	private static String toArraysAsList(String line) {
		line = line.replaceAll("\\s+", "");
		String[] parts = line.split("(\\[)|(\\],)|(\\]])");
		StringBuilder sb = new StringBuilder();
		boolean isFirst = true;
		for (int i = 0; i < parts.length; i++) {
			String p = parts[i];
			if (!p.trim().isEmpty()) {
				if (!isFirst) {
					sb.append(", ");
				}
				else {
					isFirst = false;
				}
				sb.append(String.format("Arrays.asList(%s)", p));
			}			
		}
		return sb.toString();
	}
}